//
//  ColorExtension.swift
//  foreign_swift
//
//  Created by hdr on 15-4-11.
//  Copyright (c) 2015年 hdr. All rights reserved.
//

import UIKit

extension UIColor{
    
    
    class func makeWithIntRGB(red:Int,_ green:Int,_ blue:Int)->UIColor {
        return UIColor(red: CGFloat(red)/255, green: CGFloat(green) / 255, blue: CGFloat(blue) / 255, alpha: 1.0)
    }
    
    class var normalBlueBtn:UIColor{
        return makeWithIntRGB(8,152,255)
    }
    
    class var normalRedBtn:UIColor{
        return makeWithIntRGB( 255,  102,  102)

    }
    
    class var themeColor:UIColor {
        return makeWithIntRGB(8, 152, 255)
    }
    
    class func colorWithHexString(var hexString:String)->UIColor {
        if hexString.length < 6 {
            return UIColor.clearColor()
        }
        if hexString.hasPrefix("0X") {
            hexString = hexString.substringFromIndex(2)
        }else if hexString .hasPrefix("#"){
            hexString = hexString.substringFromIndex(1)
        }

        let redString = hexString.substringWithRange(Range<Int>(start: 0, end: 2))
        
        let greenString = hexString.substringWithRange(Range<Int>(start: 2, end: 4))
        
        let blueString = hexString.substringWithRange(Range<Int>(start: 4, end: 6))
        
        var redInt = UnsafeMutablePointer<UInt32>.alloc(1)
        var greenInt = UnsafeMutablePointer<UInt32>.alloc(1)
        var blueInt = UnsafeMutablePointer<UInt32>.alloc(1)

        NSScanner(string: redString).scanHexInt(redInt)
        NSScanner(string: greenString).scanHexInt(greenInt)
        NSScanner(string: blueString).scanHexInt(blueInt)
        
        return self.makeWithIntRGB(Int(redInt.memory), Int(greenInt.memory), Int(blueInt.memory))
        
    }

}